package com.qfmy.web.app.controller.user;

import com.qfmy.common.login.CodeResult;
import com.qfmy.common.result.Result;
import com.qfmy.model.entity.user.UserInfo;
import com.qfmy.model.query.user.LoginQuery;
import com.qfmy.model.vo.user.LoginVo;
import com.qfmy.model.vo.user.UserInfoVo;
import com.qfmy.web.app.service.user.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.controller.user
 * @date 2025/10/30
 * @description 用户信息
 */
@RestController
@RequestMapping("/app/userInfo")
public class UserInfoController {

    /**
     * 注入用户service
     */
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 微信登入
     */
    @RequestMapping("/login/wxLogin")
    public Result<LoginVo> wxLogin(@RequestBody LoginQuery loginQuery) {
        LoginVo loginVo =  userInfoService.WxLogin(loginQuery);
        return Result.ok(loginVo);
    }

    /**
     * 手机号登入
     */
    @RequestMapping("/login/phoneLogin")
    public Result<LoginVo> phoneLogin(@RequestBody LoginQuery loginQuery) {
        LoginVo loginVo =  userInfoService.phoneLogin(loginQuery);
        return Result.ok(loginVo);
    }

    /**
     * 手机号加验证码登入
     */
    @RequestMapping("/login/phoneLoginWithCode")
    public Result<LoginVo> login(@RequestBody LoginQuery loginQuery) {
        LoginVo token = userInfoService.login(loginQuery);
        return Result.ok(token);
    }


    /**
     * 获取图形验证码
     */
    @GetMapping("/login/getGraphicCode")
    public Result<CodeResult> getGraphicCode() {
        CodeResult graphicCode = userInfoService.getGraphicCode();
        return Result.ok(graphicCode);
    }

    /**
     * 生成临时登录令牌
     */
    @RequestMapping("/login/getTempLoginToken")
    public Result<String> getTempLoginToken(){
        String token = userInfoService.getTempLoginToken();
        return Result.ok(token);
    }

    /**
     * 获取用户信息
     */
    @RequestMapping("/getUserInfo")
    public Result<UserInfoVo> getUserInfo(){
        UserInfoVo userInfo = userInfoService.getUserInfo();
        return Result.ok(userInfo);
    }

    /**
     * 获取用户的二维码
     */
    @RequestMapping("/getUserQrCode")
    public Result<String> getUserQrCode() {
        String qrCode = userInfoService.getUserQrCode();
        return Result.ok(qrCode);
    }

    /**
     * 更新用户喜欢类型
     */
    @RequestMapping("/updateUserLikeType")
    public Result updateUserLikeType(@RequestParam String categoryName) {
        userInfoService.updateUserLikeType(categoryName);
        return Result.ok();
    }

    /**
     * 充值vip
     */
    @RequestMapping("/rechargeVip")
    public Result rechargeVip(@RequestParam double amount, @RequestParam Integer day) {
        userInfoService.rechargeVip(amount, day);
        return Result.ok();
    }

    /**
     * 更新用户头像
     */
    @GetMapping("/updateUserAvatar")
    public Result updateUserAvatar(@RequestParam String avatar) {
        userInfoService.updateUserAvatar(avatar);
        return Result.ok();
    }

    /**
     * 更新用户信息
     */
    @PostMapping("/updateInfo")
    public Result updateUserInfo(@RequestBody UserInfo userInfo) {
        userInfoService.updateUserInfo(userInfo);
        return Result.ok();
    }

    /**
     * 进行注销账号
     */
    @GetMapping("/logout")
    public Result logout() {
        userInfoService.logout();
        return Result.ok();
    }

    /**
     * 获取今日阅读时间
     */
    @GetMapping("/getTodayReadTime")
    public Result<BigDecimal> getTodayReadTime() {
        BigDecimal readTime = userInfoService.getTodayReadTime();
        return Result.ok(readTime);
    }

    /**
     * 更新用户的今日阅读时间
     */
    @GetMapping("/updateTodayReadTime")
    public Result updateTodayReadTime(@RequestParam Integer readTime,@RequestParam Integer type) {
        userInfoService.updateTodayReadTime(readTime,type);
        return Result.ok();
    }

}
